package cn.wolfcode.rbac.controller;

import cn.wolfcode.rbac.pojo.Department;
import cn.wolfcode.rbac.pojo.Role;
import cn.wolfcode.rbac.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequestMapping("/list")
    public String selectRole(Model model) {
        List<Role> roles = roleService.selectRole();
        model.addAttribute("roles", roles);
        return "role/list";
    }

    @RequestMapping("/input")
    public String input(Integer id, Model model) {
        if (id != null) {
            Role role = roleService.selectbyid(id);
            model.addAttribute("role", role);
        }
        return "role/input";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Role role) {
        //保存或修改
        roleService.save(role);
        return "redirect:/role/list";
    }

    @RequestMapping("/delete")
    public String delect(Integer id) {
        roleService.delect(id);
        return "redirect:/role/list";
    }
}
